package com.ln.cmsln.controller.bai;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ln.cmsln.pojo.entity.bai.Permission;
import com.ln.cmsln.service.bai.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/pc")
@CrossOrigin
public class PerController {
	
	@Autowired
	UserService userService;
	
	@RequestMapping("/findall")
	public Object findPer(){
		List<Permission> list =new ArrayList<>();
		//根节点  父节点
		Permission permission = userService.getper();
		
		findInfo(permission);
		
		list.add(permission);
		return list;
			
	}
	
	//根据父节点id查询子节点，id=pid	
	private void findInfo(Permission permission){
			List<Permission> list2 = userService.findbyidchild(permission);	
			//if(list2 != null){
				for (Permission permission2 : list2) {
					permission.getChildren().add(permission2);
					findInfo(permission2);
				}
			//}
	}
	@RequestMapping("/finAllPre")
	public Object finAllPre(){
		List<Permission> list = userService.finAllPre();
		HashMap<String, Object> map = new HashMap<>();
		map.put("code", 0);
		map.put("count", 0);
		map.put("data", list);
		return map;

	}
}
